package com.second.app.thread.线程基础.day02;

/**
 * @Author GYZ
 * @Date 2023/11/17
 * <pre>
 *  观察sleep的效果
 *     案例1： 直接调用run方法，线程即为main线程
 *     案例2： 调用线程的start方法
 * </pre>
 */
public class SleepDemo {

    public static void main(String[] args) {
        class ThreadA extends Thread{
            @Override
            public void run() {
                try {
                    System.out.println("run ThreadName="+currentThread().getName()+"，begin");
                    Thread.sleep(5000);
                    System.out.println("run ThreadName="+currentThread().getName()+"，end");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        class ThreadB extends Thread{
            @Override
            public void run() {
                try {
                    System.out.println("run ThreadName="+currentThread().getName()+"，begin");
                    Thread.sleep(5000);
                    System.out.println("run ThreadName="+currentThread().getName()+"，end");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        System.out.println("----案例1----");
        ThreadA threadA = new ThreadA();
        System.out.println("begin="+System.currentTimeMillis());
        threadA.run();
        System.out.println("end="+System.currentTimeMillis());
        System.out.println("----案例2----");
        ThreadB threadB = new ThreadB();
        System.out.println("begin="+System.currentTimeMillis());
        threadB.start();
        System.out.println("end="+System.currentTimeMillis());
    }
}
